<%--
  Created by IntelliJ IDEA.
  User: kkk
  Date: 2022/8/14
  Time: 10:10
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <base href="${pageContext.request.contextPath}/">
    <script src="js/jquery.js"></script>
</head>
<body>
    <form action="AddCard_Servlet">
        <table border="1">
            <tr><th colspan="2"><h2>添加门禁卡信息</h2></th></tr>
            <tr>
                <td>持卡人姓名(*)</td>
                <td><input type="text" id="userName" name="userName"></td>
            </tr>
            <tr>
                <td>持卡人身份证号(*)</td>
                <td><input type="text" id="idNumber" name="idNumber" onblur="checkExists(this.value)"></td>
            </tr>
            <tr>
                <td>办卡日期(*)</td>
                <td><input type="text" id="date" name="date"><span id="span"></span></td>
            </tr>
            <tr><td colspan="2"><input type="submit"></td></tr>
        </table>
    </form>

</body>
    <script>
        $(function () {
            $("form").submit(function () {
                var dateTime=/^\d{4}\-(0?[1-9]|1[012])\-(0?[1-9]|[12][0-9]|3[01])$/;
                if ($('#userName').val()=="" || $('#idNumber').val()==""|| $('#date').val()=="") {
                    alert("请填写完整的门禁卡信息！");
                    return false;
                }else if (dateTime.test($('#date').val())===false){
                    alert("日期格式不正确！");
                    return  false;
                }
                return true;
            })
        })
        function checkExists(identity){
            $.post("VerifyInNumber_Servlet","idNumber="+identity,function(data){
                if (data==="true") {
                    $('#span').html("该员工已持卡");
                    return false;
                }else {
                    $('#span').html("");
                }
            },"text")
        }
        // function IdBlur() {
        //     var identity=$("#idNumber").val();
        //     $.ajax({
        //         url:"CheckIdNumber_Servlet",
        //         type:"post",
        //         data:"idNumber="+identity,
        //         dataType:"text",
        //         success:function (data) {
        //             if (data==="true") {
        //                 $('#span').html("该员工已持卡");
        //                 return false;
        //             }else {
        //                 $('#span').html("");
        //             }
        //         }
        //     })
        // }
    </script>
</html>
